/*
 * @Author: mm.yang 
 * @Date: 2018-05-09 15:02:53 
 * @Last Modified by: mm.yang
 * @Last Modified time: 2018-05-10 17:36:37
 */

const Controller = require('egg').Controller;

class NewsController extends Controller {
  async lista() {
    // const dataList = {
    //   list: [
    //     { id: 1, title: 'this is news 1', url: '/news/1'},
    //     { id: 2, title: 'this is news 2', url: '/news/2'}
    //   ]
    // };
    // 从service获取data
    const page = this.ctx.query.page || 1;
    const dataList = await this.ctx.service.news.list(page);
    console.log('dataList',dataList);
    await this.ctx.render('news/list.tpl', {list: dataList})
  };
  async listb() {
    const dataList = {
      list: [
        { id: 1, title: 'this is news 3', url: '/news/3'},
        { id: 2, title: 'this is news 4', url: '/news/4'}
      ]
    };
    await this.ctx.render('news/list.tpl', dataList)
  }
}

module.exports = NewsController
